﻿package  {
	
	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	
	public class flame_tower extends MovieClip {

		var dir:int;
		var lg:int;
		var ciclo:Timer;
		var llamas:Array=new Array();
		var valor:int=0;
		var inc:int=1;

		
		public function flame_tower(x_:int, y_:int, _dir:int, _lg:int) {
			
			dir=_dir;
			lg=_lg;
			this.x=x_;
			this.y=y_;
			this.gotoAndStop(dir);
			
			
			
			
			
		}
		function set_time(_time:int):void{

			ciclo=new Timer(_time,2);
			ciclo.start();
			ciclo.addEventListener(TimerEvent.TIMER_COMPLETE,ft_ciclo);			
			
		}
		
		function crear_flama(_lg:int):void{
			
			
			for(var i=1; i <= _lg; i++){
				
				var flm:flames=new flames();
				addChild(flm);
				
				llamas.push(flm);
				switch(dir){
					case 1:flm.x=i*32;break;
					case 2:flm.y=-i*32;break;
					case 3:flm.x=-i*32;break;
					case 4:flm.y=i*32;break;
					
				}
				
				
				flm.gotoAndStop(13);
			}
			
			if(lg>0){
				var aux:flame_tower=new flame_tower(0,0,dir,0);
				addChild(aux);
				
			}
			lg=_lg;
		/*	for(var i=1; i < lg+1; i++){
				switch(dir){
					case 1:llamas[i]=i*this.width;break;
					case 2:llamas[i]=-i*this.height;break;
					case 3:llamas[i]=-i*this.width;break;
					case 4:llamas[i]=i*this.height;break;
					
				}
			}*/
			
			switch(dir){
					case 1:llamas[0].gotoAndStop(1);break;
					case 2:llamas[0].gotoAndStop(4);break;
					case 3:llamas[0].gotoAndStop(7);break;
					case 4:llamas[0].gotoAndStop(10);break;
					
				}
			
		}
		
		function ft_ciclo(e:TimerEvent){
			
			if(inc>0){
				for(var i=0;i<lg-1;++i){
				
					
				switch(dir){
					case 1:llamas[i].gotoAndStop(2);break;
					case 2:llamas[i].gotoAndStop(5);break;
					case 3:llamas[i].gotoAndStop(8);break;
					case 4:llamas[i].gotoAndStop(11);break;
					
				}
			
				}
				llamas[(lg-1)].gotoAndStop((dir)*3);
				inc*=-1;
				
			}else{
				for(var j=1;j<lg;++j){
				
					llamas[j].gotoAndStop(13);
			
				}
				llamas[0].gotoAndStop((dir-1)*3+1);
				inc*=-1;
				
			}
			ciclo.start();
		}

	}
	
}
